//
//  BaseTableViewController.swift
//  Weibo
//
//  Created by mac on 16/3/11.
//  Copyright © 2016年 hw.chow. All rights reserved.
//

import UIKit

/*
OC中经典面试题
OC中有多继承吗？如果没有，用什么替代？协议
OC中没有实现必选的的协议方法，会报警高，但是在Switf中没有实现必选的的协议方法，会报错
*/
class BaseTableViewController: UITableViewController,visitorLoginViewDelegate {

    
    //定义用户是否登录的标识
    var userLogin = UserAccount.loadUserAccount() != nil
    
    //访客视图(包装成了属性)
    var visitorLoginView : VisitorLoginView?
    
    /*
    1.loadView 是苹果专门为手写代码准备的，一旦实现该方法，sb/xib会自动失效
    2.准备视图层次结构，在UIViewController中，会将view准备出来
    */
    override func loadView() {
        //自定义 view
        if userLogin {

            //创建tableView
            super.loadView()
            print(view)
            
        }else{
            //自定义访客视图
            visitorLoginView = VisitorLoginView()
            
            //设置代理
            visitorLoginView?.visitorViewDelegate = self
            
            view = visitorLoginView
        }
    }
    
    //MARK: 实现 VisitorLoginViewDelegate 协议方法
    func userWillLogin() {
        print(__FUNCTION__)
        
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        //模态出一个控制器，跳转到授权页面
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    func userWillRegist() {
        print(__FUNCTION__)
    }
    
    
    //会在viewWillLayoutSubviews方法中，设置view的大小
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        print(view)
        
        print(view.classForCoder)
    }
    
    

    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

    /*
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)

        // Configure the cell...

        return cell
    }
    */

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
